<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <meta charset="UTF-8">
    <title></title>
    <link href="https://cdn.bootcss.com/mui/3.7.1/css/mui.min.css" rel="stylesheet">
    <link rel="stylesheet" href="http://1.xinli2017.applinzi.com/login/iconfont/iconfont.css">
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/mui/3.7.1/js/mui.min.js"></script>
    <style type="text/css">
        body{
            background:#23a4ed;
            color: #fff;
            font-size: 26px;

        }
        .success{
            height: 500px;
            width: 100%;
            position: relative;

        }
        .success_y {
            height: 100px;
            width: 100px;
            background: #fff;
            border-radius: 50%;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%,-50%);
            text-align: center;
        }
        .success_y span{
            font-size: 40px;
            font-weight: bold;
            color: #23a4ed;
            line-height: 100px;

        }
        .title{
            height: 40px;
            text-align: center;
            width: 100%;
            position: absolute;
            top: 71%;
            left: 50%;
            transform: translate(-50%,-50%);
        }
        .error{
            height: 500px;
            width: 100%;
            position: relative;

        }
        .error_x {
            height: 100px;
            width: 100px;
            background: #fff;
            border-radius: 50%;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%,-50%);
            text-align: center;
        }
        .error_x span{
            font-size: 40px;
            font-weight: bold;
            color: #23a4ed;
            line-height: 100px;

        }
        .pay_resp_desc{
            margin-top: 1rem;
        }
    </style>
</head>
<body>
<script type="text/javascript">
    /*
 * @Author: fangzhi
 * @Date: 2018-04-20 10:37:38
 * @Last Modified by: fangzhi
 * @Last Modified time: 2018-05-21 17:54:07
 */

    /**
     * 初始化jsbridge
     * @param readyCallback 初始化完成后的回调
     */
    function initJsBridge(readyCallback) {
        var u = navigator.userAgent;
        var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
        var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
        // 注册jsbridge
        function connectWebViewJavascriptBridge(callback) {
            if (isAndroid) {
                if (window.WebViewJavascriptBridge) {
                    callback(WebViewJavascriptBridge)
                } else {
                    document.addEventListener(
                        'WebViewJavascriptBridgeReady'
                        , function () {
                            callback(WebViewJavascriptBridge)
                        },
                        false
                    );
                }
                return;
            }
            if (isiOS) {
                if (window.WebViewJavascriptBridge) {
                    return callback(WebViewJavascriptBridge);
                }
                if (window.WVJBCallbacks) {
                    return window.WVJBCallbacks.push(callback);
                }
                window.WVJBCallbacks = [callback];
                var WVJBIframe = document.createElement('iframe');
                WVJBIframe.style.display = 'none';
                WVJBIframe.src = 'https://__bridge_loaded__';
                document.documentElement.appendChild(WVJBIframe);
                setTimeout(function () {
                    document.documentElement.removeChild(WVJBIframe)
                }, 0)
            }
        }
        // 调用注册方法
        connectWebViewJavascriptBridge(function (bridge) {
            if (isAndroid) {
                bridge.init(function (message, responseCallback) {
                    console.log('JS got a message', message);
                    responseCallback(data);
                });
            }

            // 只有在这里注册过的方法，在原声代码里才能用callHandler的方式调用
            bridge.registerHandler('backClick', function (data, responseCallback) {
                showResponse(data);
            });
            if(readyCallback){
                readyCallback();
            }

        });
    }

    initJsBridge(function(){
        console.log("注册js交互事件成功！");
    });

    $('.title').click(function(){
        // IOS和android采用了不同的JS交互方式 这里区分
        var u = navigator.userAgent;
        var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
        if(!isAndroid){
            window.WebViewJavascriptBridge.callHandler('backClick', null, function (response) {
                showResponse(response);
            })
        }else{
            window.android.invokeMethod(1,[true]);
        }
    })
</script>

<script type="text/javascript">

</script>
</body>
</html>
